
import java.util.Scanner;
import java.util.Stack;

//String s = "(combine (combine (combine \"a()def\" \"cd\") \"cd\") (combine \"abcdef\" \"cd\"))";
//s = "(reverse \"a b c\")";
//s = "(search \"abcdef\" \"cd\")";
//s = "(search (combine \"123456\" \"abcdefgh\" \"123566\") (reverse \"dc\"))";
//(quote (search (combine "1234567890" "abcdefgh" "1234567890") (reverse "dc")))

//(quote "a bccd") "a bccd"
//(reverse "d c") "c d"
//(combine "cd" "fe" "ed") "cdfeed"
//(search "abcde" "cd") "cde"

public class Main2 {

	public static void main(String[] args) {
		Stack<Character> stk = new Stack<>();
		StringBuilder sb = new StringBuilder();

		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String s = sc.nextLine();
			
			for (int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);
				if (c != ')') {
					stk.add(c);
				} else if (c == ')') {
					sb.delete(0, sb.length());
					while (stk.peek() != '(') {
						sb.append(stk.pop());
					}
					stk.pop();
					String res = calc(sb.reverse().toString());
					sb.delete(0, sb.length());
					for (int j = 0; j < res.length(); j++) {
						stk.add(res.charAt(j));
					}
				}
			}
			
			while (!stk.isEmpty()) {
				sb.append(stk.pop());
			}
			System.out.println(sb.reverse().toString());

		}
		sc.close();
	}

	private static String calc(String s) {
		String res = null;
		if (s.indexOf("quote") != -1) {
			res = s.substring(6).replaceAll("\"", "");
		} else if (s.indexOf("reverse") != -1) {
			res = new StringBuilder(s.substring(8).replaceAll("\"", "")).reverse().toString();
		} else if (s.indexOf("search") != -1) {
			String[] a = s.substring(7).split("\"\\s{1}\"");
			a[0] = a[0].replaceAll("\"", "");
			a[1] = a[1].replaceAll("\"", "");
			res = a[0].substring(a[0].indexOf(a[1]));
		} else if (s.indexOf("combine") != -1) {
			res = s.substring(8).replaceAll("\"\\s{1}\"", "").replaceAll("\"", "");
		}
		return "\"" + res + "\"";
	}

}
